/**
 * @author 刘超
 * 名称: 简单的通用JS控件
 * @version 2.0
 * @Note 该插件准备直接添加在相应的对象中
 */
SU = {};
SU.get = function (id){ // 简化document.getElementById()
        var obj = null;
        if(SU.type(id) == "String"){
            obj = document.getElementById(id);
        }else{
            alert("ID必须是字符串!");
        }
        return obj;
    };
SU.type = function (obj){ // 判断数据类型

        if((typeof obj=='object')&&obj.constructor==Array){
            return ("Array");
        }
        if((typeof obj=='string')&&obj.constructor==String){
            return ("String");
        }
        if((typeof obj=='number')&&obj.constructor==Number){
            return ("Number");
        }
        if( (typeof obj=='object')&&obj.constructor==Date){
            return ("Date");
        }
        if((typeof obj=='function')&&obj.constructor==Function){
            return ("Function");
        }
        if((typeof obj=='object')&&obj.constructor==Object){
            return ("Object");
        }

    };


/*********************给String对象添加方法*****************************/

String.prototype.trim = function (){ // 去除字符串两端空格
    return this.replace(/(^\s+)|(\s+$)/g, "");
};
/**
 *
 * @param {Object} str String or char
 * @param {Object} res [reservations] 字符串剩余几位的时候停止去除
 */
String.prototype.trimLeft = function (str,res){
	var s = this;
	if(arguments.length == 0){
        while(s.indexOf(" ") == 0){
            s = s.replace(" ","");
		}
	}
	if(arguments.length == 1){
        while(s.indexOf(str) == 0){
            s = s.replace(str,"");
        }
	}
	if(arguments.length == 2){
        while(s.indexOf(str) == 0 && s.length > res){
            s = s.replace(str,"");
        }
    }
	return s;
};
String.prototype.replaceAll = function (str,rep){
	return this.replace(new RegExp(str,"gm"),rep);
};
/**
 * Remove html tags in string
 */
String.prototype.domText = function (){
	return this.replace(/<.+?>/gim,'');
};
/*********************给Object对象添加方法*****************************/
//在和持续时间插件使用时有冲突
/* 
Object.prototype.toString = function (){
	var s = "{";
	if(this){
		for(var atrr in this){
			s += atrr + ":";
			s += this[atrr];
			s += ",";
		}
	}
	var len = s.lastIndexOf(",");
	if(len > -1){
        s = s.substring(0,len);
	}
	s += "}";

	return s;
}*/
